package com.yc.booktable.web;
import com.yc.booktable.entity.AdminUser;
import com.yc.booktable.entity.Bookinfo;
import com.yc.booktable.mapper.BookinfoMapper;
import com.yc.booktable.service.impl.BookinfoServiceImpl;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
public class bookinfoAction {
    @Resource
    private BookinfoMapper bookinfoMapper;
    @Resource
    private BookinfoServiceImpl bookinfoService;

    @RequestMapping("typography")
    public String bookinfo(Model model, HttpSession session){
        AdminUser user = (AdminUser) session.getAttribute("loginedUser");
        if(user==null|| user.getState()==1){
            return "redirect:/login";
        }
        model.addAttribute("user",user);
        List<Bookinfo> bookinfons = bookinfoMapper.selectList(null);
        model.addAttribute("bookinfo",bookinfons);
        return "typography";
    }
    /*@RequestMapping("/deletebi/{bid}")
    public String move(@PathVariable("bid") int bid){
        try {
            System.out.println("删除");
            bookinfoService.removeById(bid);
            return "redirect:/typography";
        } catch ( Exception e){
            e.printStackTrace();
            return "error";
        }
    }*/
    /**
     * 处理预约
     */
    @GetMapping("/querybi")
    public String querybi(Integer id,Model model){
        Bookinfo bi = bookinfoService.getById(id);
        model.addAttribute("bi",bi);
        return "deal";
    }
    @PostMapping("updatebi")
    public String update(Bookinfo bi){
        bi.setStatus(1);
        bookinfoService.saveOrUpdate(bi);
        return "redirect:/typography";
    }
}
